package metier.sess;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import metier.entities.Industrie;



@Stateless(name="Industrie")
public class IndustrieEJBImpl implements IIndustrieLocal,IIndustrieRemote{
	@PersistenceContext(unitName="PU_Cargaison")
	private EntityManager em;

	@Override
	public void addIndustrie(Industrie i) {
		
		em.merge(i);
		
	}

	
	@Override
	public List<Industrie> getAllIndustrie() {
		Query req=em.createQuery("select i from Industrie i");
		return req.getResultList();
	}
	
	@Override
	public List<Industrie> getAllActiveIndustrie() {
		Query req=em.createQuery("select i from Industrie i where statut=true");
		return req.getResultList();
	}

	
	@Override
	public Industrie getIndustrie(Integer Id) {
		Industrie in=em.find(Industrie.class, Id);
		return in;
	}

	@Override
	public void updateIndustrie(Industrie i) {
		
		em.merge(i);
		
	}

	@Override
	public void deleteIndustrie(Integer Id) {
		Industrie i=getIndustrie(Id);
		em.remove(i);
		
	}
	

}
